package com.river;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;

import java.io.IOException;

/**
 * Created by jl on 2018/3/20.
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        IDemoService demoService = new DemoService();

        ApplicationConfig application = new ApplicationConfig();
        application.setName("provider-hello");

        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://172.168.1.122:41802");
        registry.setUsername("");
        registry.setPassword("");

        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(20880);
        protocol.setThreads(200);

        ServiceConfig<IDemoService> demoServiceServiceConfig = new ServiceConfig<IDemoService>();
        demoServiceServiceConfig.setApplication(application);
        demoServiceServiceConfig.setRegistry(registry);
        demoServiceServiceConfig.setProtocol(protocol);
        demoServiceServiceConfig.setInterface(IDemoService.class);
        demoServiceServiceConfig.setRef(demoService);
        demoServiceServiceConfig.setVersion("1.0.0");
        demoServiceServiceConfig.export();

        System.out.println("provider started");
        try {
            System.in.read();	// 按任意键退出
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
